package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.Account;
import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.SavingsAccount;
import com.acme.bankapp.domain.bank.CheckingAccount;
import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.domain.bank.Gender;

// TODO [MY] Method printMaximumAmountToWithdraw is  not implemented.
public class BankService {

	static void addClient(Bank bank, Client client)
	{
		bank.addClient(client);
	}
	
	public static void generateClients(Bank bank, int number)
	{
		for (int i = 0; i < number; i++)
		{
			addClient(bank, generateClient());
		}		
	}
	
	public static Client generateClient()
	{
		String[][] names = { {"Andrey","Ivan","Gleb","Vasiliy","Oleg","Stanislav"},
				 {"Diana","Olga","Alexandra","Natalia","Maria"} };
		
		Account newAccount = Math.random() < 0.5 ? new SavingsAccount(Math.random() * 100) : new CheckingAccount(Math.random() * 100, Math.random() * 100);
		Gender newGender = Math.random() < 0.5 ? Gender.MALE : Gender.FEMALE; 
		String newName = names[newGender.ordinal()][((int)(Math.random()*100)) % names[newGender.ordinal()].length];
		
		return new Client(newName, newGender, newAccount);		
	}	
	
	static void modifyBank(Bank bank) 
	{
		for (int i = 0; i < bank.numClients(); i++) 
		{
			if (Math.random() < 0.5) 
			{
				double amount = Math.random() * 50;
				if (Math.random() < 0.5) 
				{
					bank.getClient(i).getAccount().withdraw(amount);
				} 
				else 
				{
					bank.getClient(i).getAccount().deposit(amount);
				}
			}
		}
	}
	
	static void printMaximumAmountToWithdraw(Bank bank) 
	{
		System.out.println("List of clients:");
		for (int i = 0; i < bank.numClients(); i++) 
		{
			System.out.println(bank.getClient(i).getClientSalutation()+": "+bank.getClient(i).getAccount().maximumAmountToWithdraw());
		}
		System.out.println("");
	}		
	
}
